<?php

//品牌控制器
class BrandController extends AuthController{
	private $model;
	
	public function __init(){
		parent::__init();
		$this->model=K('Brand');
	}
	//品牌列表
	public function index(){
		$brandData=$this->model->all();
		
		$this->assign('brandData',$brandData);
		
		$this->display();
	}
	
	//添加品牌
	public function add(){
		if(IS_POST){
			//模型自动验证
			if(!$this->model->brandadd()){
				$this->error($this->model->error);
			}
			$this->success('添加成功',U('Admin/Brand/index'));
		}
		$this->display();
	}
	
	//删除品牌
	public function del(){
		$bid=Q('get.bid',0,'intval');
		$this->model->where("bid={$bid}")->delete();
		$this->success('删除成功',U('Admin/Brand/index'));
	}
	
	//编辑品牌
	public function edit(){
		$bid=Q('get.bid',0,'intval');
		$oldData=$this->model->where("bid={$bid}")->all();
		$this->assign('oldData',$oldData);
		
		if(IS_POST){
			$bid=Q('post.bid',0,'intval');
		    //如果编辑失败
			if(!$this->model->brandedit()){
				$this->error($this->model->error);
			}
			
			$this->model->where("bid={$bid}")->update();
			
			$this->success('编辑成功',U('Admin/Brand/index'));
		}
		
		
		$this->display();
	}
	
}


?>